package com.cake.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cake.base.util.ReturnUtils;
import com.cake.entity.XxMember;
import com.cake.service.inter.IXxMemberService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@RestController
@RequestMapping(value = "member")
public class MemberController {

	@Autowired
	private IXxMemberService xxMemberService;
	
	/**
	 * 查询所有的会员等级记录
	 * @return
	 * @throws Exception 
	 */
	@PostMapping(value = "selectMembers")
	public Object  selectMembers(@RequestBody XxMember xxMember) throws Exception{
		PageHelper.startPage(xxMember.getCurrentPage(), xxMember.getPageSize());
		List<XxMember> list = xxMemberService.selectByAttributeAnd(xxMember);
		PageInfo<XxMember> page = new PageInfo<>(list);
		return ReturnUtils.forNoramlPage("000000", list, 
				page.getPageNum(), page.getPageSize(), page.getPages(), (int)page.getTotal());
	}
	
	/**
	 * 根据id查询一条会员等级详情
	 * @return
	 * @throws Exception 
	 */
	@GetMapping(value = "selectMemberById")
	public Object selectMemberById(Long memberId) throws Exception{
		return ReturnUtils.forNoramlSuccess(xxMemberService.selectByPrimaryKey(memberId));
	}
	
	/**
	 * 修改一条会员等级信息
	 * @param xxMemberRank
	 * @return
	 * @throws Exception 
	 */
	@PostMapping(value = "updateMember")
	public Object updateMember(@RequestBody XxMember xxMember) throws Exception{
		return ReturnUtils.forNoramlSuccess(xxMemberService.updateByPrimaryKeySelective(xxMember));
	}
	
}
